package offer;

public class offer_0068_1 {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        if(p.val<q.val) return search(root,p,q);
        return search(root,q,p);
    }
    public TreeNode search(TreeNode node,TreeNode p,TreeNode q){
        if(node.val<p.val){
            return search(node.right,p,q);
        }
        else if(node.val>q.val){
            return search(node.left,p,q);
        }
        return node;
    }
}
